import { Asset } from "cc";
export type CompleteCallback<T = any> = (data?: T | null) => void;
// LoadResArgs方法的参数结构
export interface LoadResArgs {
    bundle: string;
    path: string;
    type: typeof Asset;
    callback: CompleteCallback;
    autoRelese?: boolean;
    cacheTme?: number;
    saveKey?: string;
}
//LoadSpriteFrameArgs方法的参数结构
export interface LoadSpriteFrameArgs {
    bundle: string;
    path: string;
    callback: CompleteCallback;
    autoRelese?: boolean;
    cacheTme?: number;
    saveKey?: string;
}
export class ArgsParseUtils {


    /**
     * loadRes方法的参数预处理
     * @returns LoadResArgs
     */
    public static _makeLoadResArgs(): LoadResArgs {
        if (arguments.length < 1 || typeof arguments[0] != "string") {
            console.error(`_makeLoadResArgs error ${arguments}`);
            return null;
        }
        let ret: LoadResArgs = { bundle: arguments[0], path: arguments[1], type: arguments[2], callback: arguments[3], autoRelese: false, cacheTme: 10, saveKey: null };
        for (let i = 4; i < arguments.length; ++i) {
            if (i == 4 && typeof arguments[i] == "boolean") {
                ret.autoRelese = arguments[i];
            } if (i == 5 && typeof arguments[i] == "number") {
                ret.cacheTme = arguments[i];
            } else if (i == arguments.length - 1 && typeof arguments[i] == "string") {
                ret.saveKey = arguments[i];
            }
        }
        return ret;
    }


    /**
     * loadSpriteFrame方法的参数预处理
     * @returns LoadSpriteFrameArgs
     */
    public static _makeloadSpriteFrameResrgs(): LoadSpriteFrameArgs {
        if (arguments.length < 1 || typeof arguments[0] != "string") {
            console.error(`_makeloadSpriteFrameResrgs error ${arguments}`);
            return null;
        }
        let ret: LoadSpriteFrameArgs = { bundle: arguments[0], path: arguments[1], callback: arguments[2], autoRelese: false, cacheTme: 10, saveKey: null };
        for (let i = 3; i < arguments.length; ++i) {
            if (i == 3 && typeof arguments[i] == "boolean") {
                ret.autoRelese = arguments[i];
            } if (i == 4 && typeof arguments[i] == "number") {
                ret.cacheTme = arguments[i];
            } else if (i == arguments.length - 1 && typeof arguments[i] == "string") {
                // 判断是不是最后一个参数use
                ret.saveKey = arguments[i];
            }
        }
        return ret;
    }
}